package org.jcb.compter;

import java.util.Timer;
import java.util.TimerTask;

import org.jcb.compter.dao.GlobalDAO;
import org.jcb.compter.model.BasicData;
import org.jcb.compter.model.User;
import org.jcb.compter.presenter.CountPresenter;
import org.jcb.compter.view.InitialView;
import org.jcb.compter.view.LearnView;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity  {
	private User user = new User("jcb");
	ThreadController workerThread ;
	private Button mquizzChineseCharacters, mlearnLevel1, buttonQuizzPinyin ;
	public static GlobalDAO globalDAO ;
	private static Context context;
	private CountPresenter countPresenter ;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i("WXW", "T1" + Thread.currentThread().getName());
        setContentView(R.layout.splash);
//        workerThread = new ThreadController();
//        workerThread.start();
//
//        initInitialMenus();
//        Log.i("WXW", "before globalDAO=" + Thread.currentThread().getName());
        globalDAO = new GlobalDAO(this);
//        Log.i("WXW", "after globalDAO=" + Thread.currentThread().getName());
//        context=getApplicationContext();
//        
        countPresenter = new CountPresenter(user ,globalDAO,this, this);
        new Timer().schedule(new DisplayTask(this,countPresenter), 2500);
        
        Log.i("WXW", "T2" + Thread.currentThread().getName());
        //setContentView(R.layout.activity_main);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
 
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}


	
	
	 public void initInitialMenus() {
	    	
	    	try {
	    		Log.i("", "view invisible=" + Thread.currentThread().getName());
				Thread.sleep(8000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	        //setContentView(R.layout.initial_menu);
	        Log.i("", "view=" + Thread.currentThread().getName());
//	        buttonQuizzPinyin = (Button) findViewById(R.id.buttonQuizzPinyin);
//	        mquizzChineseCharacters = (Button) findViewById(R.id.quizzChineseCharacters);
//	        mlearnLevel1 = (Button) findViewById(R.id.learnLevel1);
//	        
//	        buttonQuizzPinyin.setOnClickListener(new View.OnClickListener() {
//	            public void onClick(View v) {
//	                Log.d("TAG", "mAddAccountButton clicked");
//	                launchMenuQuizzPinyin();
//	            }
//	        });        
//	        
//	        
//	        mlearnLevel1.setOnClickListener(new View.OnClickListener() {
//	            public void onClick(View v) {
//	                Log.d("TAG", "mAddAccountButton clicked");
//	                launchLearn(1);
//	            }
//	        });        

	    	
	    }
	    
    

	 
	 
	 private class DisplayTask extends TimerTask {
		    Context context ;
		    CountPresenter countPresenter ;
		    	
				public DisplayTask(Context context, CountPresenter countPresenter) {
				super();
				this.context = context;
				this.countPresenter = countPresenter ;
			}

				@Override
				public void run() {
					MainActivity.this.runOnUiThread(new Runnable() {
		                public void run() {
		                	InitialView mainView = new InitialView(context, user, countPresenter);
		                	setContentView(mainView);
		                }
		            });			
				}
		    	
		    }





	 
	 
	 
}
